import { showDialog } from 'vant';
import useParameter from "@/store/parameter.js";

const BASE_URL = import.meta.env.BASE_URL;
let isThrottled = false; // 节流标志

const [parameter, setParameter] = useParameter();

const t = null;
// token 失效
export function tokenExpired() {
  if (isThrottled) return; // 如果正在节流，直接返回

  isThrottled = true; // 设置节流标志
  showDialog({
    message: '调用网格通登录异常, 请重新打开该软件',
  }).then(() => {
    const origin = location.href;
    location.href = BASE_URL + `index.html#/?parameter=${parameter.value || ''}`;

    // 如果同一个页面就再次刷新
    if (origin === location.href) {
      location.reload();
    }

    // location.href = BASE_URL + `#/?parameter=${parameter}`
  });

  // 5秒后重置节流标志
  t = setTimeout(() => {
    isThrottled = false;
    clearTimeout(t);
  }, 3000);
}